<script setup lang="ts">
import { onMounted } from 'vue'
import {
  scanQrCode,
  confirmScanQrCode,
  cancelScanQrCode,
} from '../api/scanLogin'

const params = new URLSearchParams(window.location.search.slice(1))
const id = params.get('id') as string

const confirm = () => {
  confirmScanQrCode(id).catch((error) => alert(error))
}

const cancel = () => {
  cancelScanQrCode(id).catch((error) => alert(error))
}

onMounted(async () => {
  scanQrCode(id).catch((error) => alert(error))
})
</script>

<template>
  <div>
    <p>是否登录到<span>XIAOSONG-BLOG</span></p>
    <div class="btn-group">
      <button @click="confirm" class="confirm">确认登录</button>
      <button @click="cancel" class="cancel">取消</button>
    </div>
  </div>
</template>

<style scoped>
p {
  text-align: center;
  font-size: 25px;
  margin: 0;
  color: #333;
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  line-height: 40px;
}
.btn-group {
  /* 固定到底部居中 */
  position: fixed;
  bottom: 30%;
  left: 0;
  width: 100%;
  height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

button {
  display: inline-block;
  padding: 18px 0px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  color: #fff; /* 白色文字 */
  background-color: #1f70ff; /* 稀土掘金主题蓝色 */
  border: none;
  border-radius: 13px;
  width: 280px;
}

.cancel {
  background-color: #f5f5f5;
  color: #333;
  margin-top: 20px;
}
</style>
